package com.cosina.game.robodefence.eventlistener;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.cosina.game.robodefence.R;
import com.cosina.game.robodefence.dao.RewardDao;
import com.cosina.game.robodefence.model.Reward;

public class RewardArrayAdapter extends ArrayAdapter<Reward>{
	
	
	public RewardArrayAdapter(Context context) {
		super(context, R.layout.rewarditem, RewardDao.getRewards());
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(null == convertView){
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater vi = (LayoutInflater)getContext().getSystemService(inflater);
			convertView = vi.inflate(R.layout.rewarditem, null);
			Log.e("cosina1985", "" + convertView.getClass().getName());
		}
		
		Reward reward = getItem(position);
		
		Button button = (Button)convertView.findViewById(R.id.tryUpButton);
		if(reward.hasLevel()){
			button.setText("Upgrade");
		}else{
			button.setText("Unlock");
		}
		button.setEnabled(false);
		
		TextView name = (TextView)convertView.findViewById(R.id.rewardName);
		name.setText(reward.getName());
		
		TextView rewardInfo = (TextView)convertView.findViewById(R.id.rewardInfo);
		rewardInfo.setText(reward.getInfo());
		
		TextView desc = (TextView)convertView.findViewById(R.id.rewardDesc);
		desc.setText(reward.getDesc());
		return convertView;
	}

}
